package com.gouqi.mall.controller;

import com.gouqi.mall.domain.Enterprise;
import com.gouqi.mall.domain.ProductBrand;
import com.gouqi.mall.service.EnterpriseService;
import com.gouqi.mall.service.ProductBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author xiaofei
 * @time:2020-01-12
 * @desccript:企业相关信息操作
 */
@CrossOrigin
@Api(basePath = "/api/v1", value = "企业信息", description = "操作企业信息")
@Component
@RestController
@RequestMapping(value = "/enterprise")
public class EnterpriseController extends BaseController{
    @Autowired
    @Qualifier("enterpriseServiceImpl")
    private EnterpriseService service;

    @ResponseBody
    @RequestMapping(value = "/addOneCompany.do",method = RequestMethod.POST, produces = "application/json")
    @ApiOperation(value = "新增企业信息",notes = "新增一家企业信息",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "token",value = "用户token",required = true,dataType = "String")
    })
    public String addOneCompany(@RequestHeader String token,@RequestBody @Valid Enterprise company){
        return service.addOneCompany(company);
    }

    @ResponseBody
    @RequestMapping(value = "/updateOneCompany.do",method = RequestMethod.PUT, produces = "application/json")
    @ApiOperation(value = "更新企业信息",notes = "更新一个企业信息",httpMethod = "PUT")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "token",value = "用户token",required = true,dataType = "String")
    })
    public String updateOneCompany(@RequestHeader String token,@RequestBody @Valid  Enterprise company){
        return service.updateOneCompany(company);
    }

    @ResponseBody
    @RequestMapping(value = "/deleteOneCompany.do",method = RequestMethod.DELETE, produces = "application/json")
    @ApiOperation(value = "删除企业",notes = "删除一个企业信息",httpMethod = "DELETE")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "token",value = "用户token",required = true,dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "id",value = "企业信息id",required = true,dataType = "Integer"),
    })
    public String deleteOneCompany(@RequestHeader String token,@RequestParam Integer id){
        return service.deleteOneCompany(id);
    }

    @ResponseBody
    @RequestMapping(value = "/queryOneCompany.do",method = RequestMethod.GET, produces = "application/json")
    @ApiOperation(value = "搜索企业",notes = "搜索一家企业信息",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "token",value = "用户token",required = true,dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "by",value = "通过什么查找",required = true,dataType = "String",defaultValue = "name"),
            @ApiImplicitParam(paramType = "query",name = "name",value = "企业名称",required = true,dataType = "String")
    })
    public String queryOneCompany(@RequestHeader String token,@RequestParam String name){
        return service.queryOneCompany(name);
    }

    @ResponseBody
    @RequestMapping(value = "/queryAllCompanies.do",method = RequestMethod.GET, produces = "application/json")
    @ApiOperation(value = "搜索企业",notes = "通过关键字名称，搜索所有的企业信息",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "token",value = "用户token",required = true,dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "index",value = "当前页",required = true,dataType = "int"),
            @ApiImplicitParam(paramType = "query",name = "pageSize",value = "每页显示条数",required = true,dataType = "int")
    })
    public String queryAllCompanies(@RequestHeader String token,Integer index,Integer pageSize){
        return service.queryAllCompanies(index,pageSize);
    }

    @ResponseBody
    @RequestMapping(value = "/getCompanyById.do",method = RequestMethod.GET, produces = "application/json")
    @ApiOperation(value = "搜索企业",notes = "通过id获取一家企业信息，包括该企业生产的产品.",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "token",value = "用户token",required = true,dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "id",value = "公司id",required = true,dataType = "int")
    })
    public String getCompanyById(@RequestHeader String token,Integer id){
        return service.getCompanyById(id);
    }
}
